package com.jd.search.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jd.search.dao.SearchDao;
import com.jd.search.pojo.SearchResult;
import com.jd.search.service.SearchService;

@Service("searchService")
public class SearchServiceImpl implements SearchService {
	@Autowired
	private SearchDao searchDao;
	@Override
	public SearchResult searchGoods(String keywords, int page, int rows) {
		try {
			SearchResult results = searchDao.searchGoods(keywords, page, rows);
			results.setPage(page);
			Integer total = (int)(results.getCount()% rows == 0?results.getCount()/rows:results.getCount()/rows+1);
			results.setTotal(total);
			return results;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
